<?php
namespace Api\Controller;
use Think\Controller;

class CateController extends BaseController {

   private $m = NULL;
   private $md = NULL;
   private $navName = '订单管理';


   public function _initialize(){
   		parent::_initialize();
		$this->m = M('shop');
		$this->md = M('shop_detail');
		
		
   }
    	 	
	/**   聚餐美食-猜你喜欢  liuq
	*
	*/	
  
   public  function slist(){
  
       //$cid = I('cid');//  用户标识  member id
       $data = $this->m->where('(shop_level_two = 4  OR  shop_level_two = 28)  AND buss_status = 2')->order('id desc')->select();      
  
       foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
              
                 }
         
    
    returnApiData2('0','成功',$data, $data2,$data3);exit;	     
       
   }
   
       /**   聚餐美食-猜你喜欢_顶部8个固定选项 liuq
	*
	*/	
     public  function slist_top_eight(){
        
         $class_id = I('class_id'); // 1，中餐（shop_product_class id 10 34） 2,特色餐厅（11 35） 3，火锅（12 36） 4，西餐厅（13 37） 5，烤肉（17 41 ）6，茶餐厅（14 38） 7，川菜（ 16 40）8，海鲜烧烤（15  39）
         if( $class_id == 1){
               $data = $this->m->where('(shop_level_three = 10  OR  shop_level_three = 34)  AND buss_status = 2')->order('id desc')->select();    
         }  elseif ( $class_id == 2 ) {
               $data = $this->m->where('(shop_level_three = 11  OR  shop_level_three = 35)  AND buss_status = 2')->order('id desc')->select();    
         }  elseif ( $class_id == 3  ) {
               $data = $this->m->where('(shop_level_three = 12  OR  shop_level_three = 36)  AND buss_status = 2')->order('id desc')->select();    
         }  elseif( $class_id == 4  )  {
               $data = $this->m->where('(shop_level_three = 13  OR  shop_level_three = 37)  AND buss_status = 2')->order('id desc')->select();    
         }  elseif( $class_id == 5 )   {
               $data = $this->m->where('(shop_level_three = 17  OR  shop_level_three = 41)  AND buss_status = 2')->order('id desc')->select();    
         } elseif( $class_id == 6 )   {
               $data = $this->m->where('(shop_level_three = 14  OR  shop_level_three = 38)  AND buss_status = 2')->order('id desc')->select();    
         } elseif( $class_id == 7 )   {
               $data = $this->m->where('(shop_level_three = 16  OR  shop_level_three = 40)  AND buss_status = 2')->order('id desc')->select();    
         } elseif( $class_id == 8 )   {
               $data = $this->m->where('(shop_level_three = 15  OR  shop_level_three = 39)  AND buss_status = 2')->order('id desc')->select();    
         }else{
             
         }
      
         foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
              
                 }
                 
      
    returnApiData2('0','成功',$data, $data2,$data3);exit;	 
       
     }
     
      public  function eight_order(){
          $class_id = I('class_id');// 商家类型 // 1，中餐（shop_product_class id 10 34） 2,特色餐厅（11 35） 3，火锅（12 36） 4，西餐厅（13 37） 5，烤肉（17 41 ）6，茶餐厅（14 38） 7，川菜（ 16 40）8，海鲜烧烤（15  39）
          $order_type  =  I('order_type'); //排序条件  1智能排序   2 离我最近   3 最新发布   4 价格最高   5 价格最高低
          
           if( $class_id == 1){
                        $data = $this->m->where('(shop_level_three = 10  OR  shop_level_three = 34)  AND buss_status = 2')->select();
                  }  elseif ( $class_id == 2 ) {
                        $data = $this->m->where('(shop_level_three = 11  OR  shop_level_three = 35)  AND buss_status = 2')->getField('id');
                  }  elseif ( $class_id == 3  ) {
                        $data = $this->m->where('(shop_level_three = 12  OR  shop_level_three = 36)  AND buss_status = 2')->getField('id');  
                  }  elseif( $class_id == 4  )  {
                       $data = $this->m->where('(shop_level_three = 13  OR  shop_level_three = 37)  AND buss_status = 2')->getField('id');
                  }  elseif( $class_id == 5 )   {
                        $data = $this->m->where('(shop_level_three = 17  OR  shop_level_three = 41)  AND buss_status = 2')->getField('id');
                  } elseif( $class_id == 6 )   {
                       $data = $this->m->where('(shop_level_three = 14  OR  shop_level_three = 38)  AND buss_status = 2')->getField('id');
                  } elseif( $class_id == 7 )   {
                       $data = $this->m->where('id="'.$item['s_id'].'" AND (shop_level_three = 16  OR  shop_level_three = 40)  AND buss_status = 2')->getField('id');
                  } elseif( $class_id == 8 )   {
                        $data = $this->m->where('id="'.$item['s_id'].'" AND (shop_level_three = 15  OR  shop_level_three = 39)  AND buss_status = 2')->getField('id');
                  }else{

                  }
                  
        if( $order_type == 1 ){
            
         foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                 
                   foreach($data as $v){  
                      $flag[] = $v['add_time'];  
                   }  
                   array_multisort($flag, SORT_ASC, $data); 
                        
            
        }          
                  
       if( $order_type == 3 ){
         foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                 
                   foreach($data as $v){  
                      $flag[] = $v['add_time'];  
                   }  
                   array_multisort($flag, SORT_DESC, $data); 
                        
                }
                
                
       if($order_type == 4){
        foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                  foreach($data as $v){  
                         $flag[] = $v['per_consumption'];  
                   }  
                  array_multisort($flag, SORT_DESC, $data); 
        }
        
        
        if($order_type == 5){
        foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                  foreach($data as $v){  
                         $flag[] = $v['per_consumption'];  
                   }  
                  array_multisort($flag, SORT_ASC, $data); 
        }
     
       returnApiData2('0','成功',$data, $data2,$data3);exit;	  
      }
      
      
      /*聚餐美食 8个分类中列表中的筛选*/
       public  function eight_choice(){
       
         $class_id = I('class_id');// 1，中餐（shop_product_class id 10 34） 2,特色餐厅（11 35） 3，火锅（12 36） 4，西餐厅（13 37） 5，烤肉（17 41 ）6，茶餐厅（14 38） 7，川菜（ 16 40）8，海鲜烧烤（15  39）
         $dinner_num_type = I('dinner_num_type'); //用餐人数
         $dinner_time_type = I('dinner_time_type'); // 用餐时段
         $dinner_service_type = I('dinner_service_type'); //餐厅服务
         if(!empty($dinner_num_type)){
             $where['dinner_num_type'] = $dinner_num_type;
         }
         if(!empty($dinner_time_type)){
             $where['dinner_time_type'] = $dinner_time_type;
         }
         if(!empty($dinner_service_type)){
             $where['dinner_service_type'] = $dinner_service_type;
         }
         
         $data = $this->md->where($where)->order('id desc')->select();
         
 
         foreach ($data as $key => $value) {
           
            $shop_level_three=M('shop')->where("id=".$value['s_id'])->getField('shop_level_three');
            $shop=M('shop')->where("id=".$value['s_id'])->find();

            //$shop_level_three=M('shop')->where("id=".$value['s_id'])->find();
            //$shop=M('shop')->where("id=".$value['s_id'])->find();

           if($class_id==1){
                if($shop_level_three==10||$shop_level_three==34){
                  $string.=$shop['id'].'|';
           }
           }
           if($class_id==2){
                if($shop_level_three==11||$shop_level_three==35){
                  $string.=$shop['id'].'|';
           }
           }
           if($class_id==3){
                if($shop_level_three==12||$shop_level_three==36){
                  $string.=$shop['id'].'|';
           }
           }
           if($class_id==4){
                if($shop_level_three==13||$shop_level_three==37){
                  $string.=$shop['id'].'|';
           }
           }
           if($class_id==5){
                if($shop_level_three==17||$shop_level_three==41){
                  $string.=$shop['id'].'|';
           }
           }
           if($class_id==6){
                if($shop_level_three==14||$shop_level_three==38){
                  $string.=$shop['id'].'|';
           }
           }
           if($class_id==7){
                if($shop_level_three==16||$shop_level_three==40){
                  $string.=$shop['id'].'|';
           }
           }
           if($class_id==8){
                if($shop_level_three==15||$shop_level_three==39){
                  $string.=$shop['id'].'|';
           }
           }
           
         }
          $array=explode("|", $string);
          array_pop($array);
          foreach ($array as $key => $value) {
           $data4[$key]['shop_name'] = M('shop')->where('id="'.$value.'"')->getField('shop_name');
              $data4[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('per_consumption');
                $data4[$key]['start_time'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('start_time'); 
                    $data4[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('stop_time'); 
                      $data4[$key]['address'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('address'); 
                         $data4[$key]['shop_heapic'] = $this->md->where('s_id="'.$value.'"')->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
  
           }
                    // if(!is_array($string)){
                    //  $ids = explode("|", $string);
                    //  foreach( $ids as $key => $item ){
                    //       $data1[$key]['id']  = $item;
                    //  }
                     
                    // }
                    // dump($data4);exit;
           returnApiData2('0','成功',$data4, $data2,$data3);exit;	 
   }
     
      /*聚餐美食 8个分类中列表中的筛选*/
      
      public function eight_choice_01(){
         $class_id = 1;// 1，中餐（shop_product_class id 10 34） 2,特色餐厅（11 35） 3，火锅（12 36） 4，西餐厅（13 37） 5，烤肉（17 41 ）6，茶餐厅（14 38） 7，川菜（ 16 40）8，海鲜烧烤（15  39）
         $dinner_num_type = 2; //用餐人数
         $dinner_time_type = 1; // 用餐时段
         $dinner_service_type = 1; //餐厅服务
         if(!empty($dinner_num_type)){
            // $where['dinner_num_type'] = $dinner_num_type;
             $condition['dinner_num_type'] = $dinner_num_type;
         }
         if(!empty($dinner_time_type)){
           //  $where['dinner_time_type'] = $dinner_time_type;
             $condition['dinner_time_type'] = $dinner_time_type;
             
         }
         if(!empty($dinner_service_type)){
            $condition['dinner_service_type'] = $dinner_service_type;
         }
          
        $data = $this->m->where($where)->order('id desc')->select();
          
        foreach ($data as $key => $item){
            
                  if( $class_id == 1){
                      $data[$key]['shop_id'] = $this->m->where('id="'.$item['id'].'" AND (shop_level_three = 10  OR  shop_level_three = 34)  AND buss_status = 2')->getField('id');  
                  }  elseif ( $class_id == 2 ) {
                        $data[$key]['shop_id'] = $this->m->where('id="'.$item['id'].'" AND (shop_level_three = 11  OR  shop_level_three = 35)  AND buss_status = 2')->getField('id');
                  }  elseif ( $class_id == 3  ) {
                        $data[$key]['shop_id'] = $this->m->where('id="'.$item['id'].'" AND (shop_level_three = 12  OR  shop_level_three = 36)  AND buss_status = 2')->getField('id');  
                  }  elseif( $class_id == 4  )  {
                       $data[$key]['shop_id'] = $this->m->where('id="'.$item['id'].'" AND (shop_level_three = 13  OR  shop_level_three = 37)  AND buss_status = 2')->getField('id');
                  }  elseif( $class_id == 5 )   {
                        $data[$key]['shop_id'] = $this->m->where('id="'.$item['id'].'" AND (shop_level_three = 17  OR  shop_level_three = 41) AND buss_status = 2')->getField('id');
                  } elseif( $class_id == 6 )   {
                       $data[$key]['shop_id'] = $this->m->where('id="'.$item['id'].'" AND (shop_level_three = 14  OR  shop_level_three = 38) AND buss_status = 2')->getField('id');
                  } elseif( $class_id == 7 )   {
                       $data[$key]['shop_id'] = $this->m->where('id="'.$item['id'].'" AND  (shop_level_three = 16  OR  shop_level_three = 40) AND buss_status = 2')->getField('id');
                  } elseif( $class_id == 8 )   {
                        $data[$key]['shop_id'] = $this->m->where('id="'.$item['id'].'" AND (shop_level_three = 15  OR  shop_level_three = 39) AND buss_status = 2')->getField('id');
                  }else{

                  }
        $condition['s_id'] =    $data[$key]['shop_id'];
        $condition['_logic'] = "and";
        
        $data[$key]['per_consumption'] = M('shop_detail')->where($condition)->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where($condition)->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where($condition)->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where($condition)->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where($condition)->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
  
              
        }
        
        print_r($data);exit;
            
      }
      
      
   
   
   
     
   
   
   
   
//         public  function  shop_detail(){
//                $mid = I('mid');
//                //$mid = 1;
//                //左侧类别信息
//                //此时时间戳
//	        $now_time = time(); 
//                //当天凌晨
//                $day_break = strtotime(date('Y-m-d'));  
//                //本月第一天时间戳
//                $month_first_day = mktime(0,0,0,date('m'),1,date('Y')); 
//                //本年第一天时间戳
//                $year_first_day = mktime(0,0,0,1,1,date("Y",time())); 
//               
//                $data = M('shop_product')->where('mid="'.$mid.'"')->select();
//                foreach ( $data as $key => $item ){
//                   $data[$key]['pic_path'] = $item['pic_path']?__VUPLOAD__.'pro/'.$item['pic_path']:""; //产品头像  
//                   $data[$key]['month_sale_num'] = M('shop_product_order_pro')->where('pro_id="'.$item['id'].'" AND add_time >="'.$month_first_day .'" AND add_time <="'.$now_time .'"')->count();
//                }
//               
//               
//               $info = M('shop_product_type')->where('mid="'.$mid.'"')->select();
//               foreach( $info as $key => $item ){
//                        $data2[$key]['type_id'] = $item['id'];
//                        $data2[$key]['type_name'] = $item['type_name'];
//               }
//              
//            
//                   $attitude = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('attitude_star'); 
//                   $speed = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('speed_star'); 
//                   $taste = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('taste_star'); 
//                   $evaluate_times = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
//                   $comment_star = round(( $attitude  + $speed + $taste )/( $evaluate_times*3 ));  
//                   
//                    
//                   if(  $comment_star == 1 ){
//                      $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."1star.png";
//                   }elseif(   $comment_star == 2  ){
//                      $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."2star.png";
//                   }elseif(   $comment_star == 3  ){
//                      $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."3star.png";
//                   }elseif(   $comment_star == 4  ){
//                      $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."4star.png";
//                   }elseif(   $comment_star == 5  ){
//                      $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."5star.png";
//                   }else{
//                       $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."6star.png";
//                   }
//                   
//                   
//                   $dataInfo =  M('shop')->where('mid="'.$mid.'"')->find();
//                   $data3['shop_name'] = $dataInfo['shop_name'];
//                   $data3['shop_intro'] = $dataInfo['shop_intro'];    
//                   $data3['address'] = M('shop_detail')->where('s_id="'.$dataInfo['id'].'"')->getField('address');
//                   $data3['telephone'] = M('shop_detail')->where('s_id="'.$dataInfo['id'].'"')->getField('telephone');
//                   $data3['class_name'] = M('shop_product_class')->where('id="'.$dataInfo['shop_level_three'].'"')->getField('class_name');
//                   $data3['shop_toppics']  =  $this->md->where("s_id=".$dataInfo['id'])->getField('shop_toppics')?__VUPLOAD__.'shop_toppics/'.$this->md->where("s_id=".$dataInfo['id'])->getField('shop_toppics'):"";    
//                   
//                   returnApiData2('0','成功',$data, $data2,$data3);exit;	
//           }
//           
      
       public  function  shop_detail(){
                   $mid = I('mid');
                   $dataInfo = $this->md->where('s_id="'.$mid.'"')->find();
                   
                   $data['shop_toppics']  =  $dataInfo['shop_toppics']?__VUPLOAD__.'shop_toppics/'.$item['shop_toppics']:"";
                   $data['shop_heapic']  =  $dataInfo['shop_heapic']?__VUPLOAD__.'shop_heapic/'.$item['shop_heapic']:"";
                   $data['shop_name'] = M('shop')->where('mid="'.$mid.'"')->getField('shop_name');
                   $data['shop_intro'] = M('shop')->where('mid="'.$mid.'"')->getField('shop_intro');    
                   $data['address'] = M('shop_detail')->where('s_id="'.$dataInfo['id'].'"')->getField('address'); 
                   $data['shop_intropics'] = $dataInfo['shop_intropics'];  
                   $data['per_consumption'] = $dataInfo['per_consumption'];   
                   $data['telephone'] = M('shop_detail')->where('s_id="'.$dataInfo['id'].'"')->getField('telephone');  
                  // $data['class_name'] = M('shop_product_class')->where('id="'.$dataInfo['shop_level_three'].'"')->getField('class_name');
                       
                   $attitude = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('attitude_star'); 
                   $speed = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('speed_star'); 
                   $taste = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('taste_star'); 
                   $evaluate_times = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                   $comment_star = round(( $attitude  + $speed + $taste )/( $evaluate_times*3 ));  
                   $data['comment_star_num'] = $comment_star;
                    
                   if(  $comment_star == 1 ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."1star.png";
                   }elseif(   $comment_star == 2  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."2star.png";
                   }elseif(   $comment_star == 3  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."3star.png";
                   }elseif(   $comment_star == 4  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."4star.png";
                   }elseif(   $comment_star == 5  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."5star.png";
                   }else{
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."6star.png";
                   }
                   
                  
                   returnApiData2('0','成功',$data, $data2,$data3);exit;	
           }
           
           
           
           
              public function   shop_detail_class(){  //  详情中左下分类筛选
                  $mid  = I('mid');
                  $typeid = I('type_id');
                  $data = M('shop_product')->where('mid="'.$mid.'" AND type_id="'.$typeid.'"')->select();
                  foreach( $data as $key => $item ){
                      
                       $data[$key]['pic_path'] = $item['pic_path']?__VUPLOAD__.'pro/'.$item['pic_path']:""; //产品头像  
                       $data[$key]['month_sale_num'] = M('shop_product_order_pro')->where('pro_id="'.$item['id'].'" AND add_time >="'.$month_first_day .'" AND add_time <="'.$now_time .'"')->count();
             
                      
                      
                  }
                  
              }
     
        public function show_evaluate(){ //商家评论
           $mid =  I('mid');  //下方循环评论
          // $mid =  1;
           $data = M('shop_evaluate')->where('mid="'.$mid.'"')->order('add_time desc')->select();
           foreach (  $data as $key => $item ){
                     
                   $every_star_total = $data[$key]['attitude_star'] + $data[$key]['speed_star'] +$data[$key]['taste_star'];
                   $data[$key]['comment_star'] = round( $every_star_total/3 );
               
                   if( $data[$key]['comment_star'] == 1 ){
                      $data[$key]['comment_star_value'] = __VUPLOAD__.'evaluate/'."1star.png";
                   }elseif(  $data[$key]['comment_star'] == 2  ){
                      $data[$key]['comment_star_value'] = __VUPLOAD__.'evaluate/'."2star.png";
                   }elseif(  $data[$key]['comment_star'] == 3  ){
                      $data[$key]['comment_star_value'] = __VUPLOAD__.'evaluate/'."3star.png";
                   }elseif(  $data[$key]['comment_star'] == 4  ){
                      $data[$key]['comment_star_value'] = __VUPLOAD__.'evaluate/'."4star.png";
                   }elseif(  $data[$key]['comment_star'] == 5  ){
                      $data[$key]['comment_star_value'] = __VUPLOAD__.'evaluate/'."5star.png";
                   }else{
                       $data[$key]['comment_star_value'] = __VUPLOAD__.'evaluate/'."null.png";
                   }
                   $phone_num = M('customer')->where('cid="'.$item['cid'].'"')->getField('phone'); 
                   $data[$key]['phone'] = substr_replace($phone_num,'****',3,4);
                   $data[$key]['heapic'] = M('customer')->where('cid="'.$item['cid'].'"')->getField('heapic')?__VUPLOAD__.'heapic/'.M('customer')->where('cid="'.$item['cid'].'"')->getField('heapic'):""; //用户头像
                   $data[$key]['evaluate_pics'] = __VUPLOAD__.'evaluate_pics/'.$item['evaluate_pics']; //evaluate_pics
           }
            
                   // 顶部总的三个评价
                            $attitude_star_total =  M('shop_evaluate')->where('mid="'.$mid.'"')->sum('attitude_star'); 
                              $attitude_star_total_count = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                                $attitude_star_num = round(   $attitude_star_total / $attitude_star_total_count ); 
                                  if(  $attitude_star_num  == 1 ){
                                     $data1['attitude_star_value'] = __VUPLOAD__.'evaluate/'."1star.png";
                                   }elseif(   $attitude_star_num  == 2  ){
                                     $data1['attitude_star_value'] = __VUPLOAD__.'evaluate/'."2star.png";
                                   }elseif(   $attitude_star_num  == 3  ){
                                     $data1['attitude_star_value'] = __VUPLOAD__.'evaluate/'."3star.png";
                                   }elseif(  $attitude_star_num  == 4  ){
                                     $data1['attitude_star_value'] = __VUPLOAD__.'evaluate/'."4star.png";
                                   }elseif(   $attitude_star_num  == 5  ){
                                    $data1['attitude_star_value'] = __VUPLOAD__.'evaluate/'."5star.png";
                                   }else{
                                    $data1['attitude_star_value'] = __VUPLOAD__.'evaluate/'."null.png";
                                   }
                      
                                $speed_star_total =  M('shop_evaluate')->where('mid="'.$mid.'"')->sum('speed_star'); 
                                  $speed_star_total_count = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                                    $speed_star_num  = round(   $speed_star_total / $speed_star_total_count );
                                   if(  $speed_star_num  == 1 ){
                                     $data1['speed_star_value'] = __VUPLOAD__.'evaluate/'."1star.png";
                                   }elseif(  $speed_star_num == 2  ){
                                     $data1['speed_star_value'] = __VUPLOAD__.'evaluate/'."2star.png";
                                   }elseif(   $speed_star_num == 3  ){
                                     $data1['speed_star_value'] = __VUPLOAD__.'evaluate/'."3star.png";
                                   }elseif(  $speed_star_num == 4  ){
                                     $data1['speed_star_value'] = __VUPLOAD__.'evaluate/'."4star.png";
                                   }elseif(   $speed_star_num  == 5  ){
                                    $data1['speed_star_value'] = __VUPLOAD__.'evaluate/'."5star.png";
                                   }else{
                                    $data1['speed_star_value'] = __VUPLOAD__.'evaluate/'."null.png";
                                   } 
                             
                               $taste_star_total =  M('shop_evaluate')->where('mid="'.$mid.'"')->sum('taste_star'); 
                                 $taste_star_total_count = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                                    $taste_star_num = round(   $taste_star_total / $taste_star_total_count );
                                     if(  $taste_star_num  == 1 ){
                                        $data1['taste_star_value'] = __VUPLOAD__.'evaluate/'."1star.png";
                                      }elseif(  $taste_star_num == 2  ){
                                        $data1['taste_star_value'] = __VUPLOAD__.'evaluate/'."2star.png";
                                      }elseif(   $taste_star_num == 3  ){
                                        $data1['taste_star_value'] = __VUPLOAD__.'evaluate/'."3star.png";
                                      }elseif(  $taste_star_num == 4  ){
                                        $data1['taste_star_value'] = __VUPLOAD__.'evaluate/'."4star.png";
                                      }elseif(   $taste_star_num  == 5  ){
                                       $data1['taste_star_value'] = __VUPLOAD__.'evaluate/'."5star.png";
                                      }else{
                                       $data1['taste_star_value'] = __VUPLOAD__.'evaluate/'."null.png";
                                      } 
                         returnApiData2('0','成功',$data, $data1,$data3);exit;	
           }

           
           
      

     
	   	     //记录帐户交易日志
    public function add_account_log($uid,$price,$log,$type,$payment,$balance){
            $addlogdata["id"]=Getmysql_Idstr(6);
			$addlogdata['user_id']=$uid;			
			$addlogdata['user_money']=$price;  
			$addlogdata['change_type']=$type; //类型 0为充值，1为提现，2为付薪资，3为退款至余额，4为做任务赚取，5为余额托管资金，6为积分托管资金，7为充值托管资金
			$addlogdata['change_desc']=$log;
			$addlogdata['payment']=$payment;    //支付方式 ID  对应payment表ID
			$addlogdata['balance']=$balance;    //变动之前的原始金额
			$addlogdata['change_time']=time();
		    $request=M('account_log')->add($addlogdata);
            return true;
			
    }
	
	/** 2016-7-12   //达人终止订单
	*
	*/	
		public function task_end(){ 
		
				$order_id = I('order_id');
				$status=M_S('order_item')->where('order_id='.$order_id)->getField('status');
				if($status==1){returnApiresult("0","订单已完成，无法终止任务");exit;}
				if($status==4){returnApiresult("0","订单已终止");exit;}
				  M_S('order_item')->where("order_id=".$order_id)->setField('status',4);
				$task_item_id=M_S('order_item')->where('order_id='.$order_id)->getField('task_item_id');
				$d_price=M_S('order_item')->where('order_id='.$order_id)->getField('d_price');
				$task_uid=M_S('order_info')->where('id='.$order_id)->getField('uid');
				if($task_item_id){
				$info_id=M_S('task_item')->where("id=".$task_item_id)->setField('status',4);   //支付定金状态修改
				$skill_id=M_S('task_item')->where("id=".$task_item_id)->getField('skill_id'); 
				}
				
				    M_S('skill')->where("id=".$skill_id)->setInc('over_num',1); //终止任务记录数
				
				if($d_price>0){
				M('member_info')->where(array('mid'=>$task_uid))->setInc('user_money',$d_price);   //将定金返回任务主账户
				M('member_info')->where(array('mid'=>$task_uid))->setDec('frozen_money',$d_price);
				$this->add_account_log($task_uid,$d_price,"任务终止返余额",3,0,$balance);//类型 达人终止任务，返回定金
				}
				if($info_id){
				returnApiresult("0","成功");exit;
				}else{	
				returnApiresult("1","失败");exit;
				}
				
	 }
	
	/** 2016-4-25 逻辑删除 
	*
	*/	
	
	public function del(){
	        $ids = I('id');
            if($ids){
			if($this->m->where("id=".$ids)->setField('status',0)){   //逻辑删除 
						//****mono删除
						$del['where']=array('id'=>$ids);
						M_G('task')->delete($del);
						//****mono删除
			 returnApiresult("0","成功");exit;
			}else{	
			 returnApiresult("1","失败");exit;
			}
			}else{
			 returnApiresult("1","参数为空");exit;
			}
	}
	
	
	/*
	############################  报名
	*/		
	
	/** 2016-4-27 任务报名
	*
	*/	
	
	public function addbm(){
	
		    $data["uid"]=$this->userid;
		    $data["task_id"]= I('post.task_id');
			$in_name=M_S('task')->where('id='.I('post.task_id'))->getField('in_name');
			if($in_name){
			$data["skill_id"]=M_S('skill')->where('uid='.$this->userid." and in_name='".$in_name."'" )->getField('id');
			}
            $data["user_name"]= M('member_info')->where('mid='.$this->userid)->getField('nickname');
			$data["skill_price"]= M_S('skill')->where('id='.$data["skill_id"])->getField('price');
			$data["create_time"]= time();	
			$infoid = $this->m_bm->add($data);
			if($infoid){ 
			 returnApiresult('0','成功');exit;
			}else{
			 returnApiresult("1","失败");exit;
			}
	}	
	

	
		/** 2016-4-27 报名审核列表 
	*
	*/	
	public function bnsh(){
	
	            $task_id = (int)I('post.task_id');
				if($task_id>0){
                $where['task_id']= $task_id;   // 
				$data = $this->m_bm->field('id,task_id,uid,number,in_id,skill_price,create_time,is_win')->where($where)->order('id desc')->select();
				foreach($data as $key=>$item){
				$data2[$key]['id'] =$item['id'];
				$data2[$key]['task_id'] =$item['task_id'];
				$data2[$key]['pic']=$this->oss_view(M('member_info')->where('mid='.$item['uid'])->getField('pic'));
				$data2[$key]['price'] =M_S('task')->where('id='.$item['task_id'])->getField('price');
				$data2[$key]['unit'] =M_S('task')->where('id='.$item['task_id'])->getField('unit');
				$data2[$key]['username']=M('member_info')->where('mid='.$item['uid'])->getField('nickname');
				$data2[$key]['sex']=M('member_info')->where('mid='.$item['uid'])->getField('sex');
				$data2[$key]['age'] = $this->birthday(date('Y-m-d',M('member_info')->where('mid='.$item['uid'])->getField('stime')));
				$data2[$key]['in_name']=M_S('task')->where('id='.$item['task_id'])->getField('in_name');
				$data2[$key]['classone']=M_S('task')->where('id='.$item['task_id'])->getField('classone');
				if($data2[$key]['classone']){
				$data2[$key]['classpic'] = M('industry_class')->where("id=".$data2[$key]['classone'])->getField('pic_path');
				}
				$data2[$key]['skill_desc'] = M_S('task')->where('id='.$item['task_id'])->getField('task_desc');	
				$data2[$key]['is_win'] = $item['is_win'];
				$data2[$key]['addtime'] = date("Y-h-d",$item['create_time']);
				}
				}else{
				returnApiresult('1','参数错误');exit;
				}
				if($data2){
				returnApiData('0','成功',$data2);exit;
				}else{
				returnApiresult('1','无记录');exit;
				}
	}
	
	
	/** 2016-4-28 任务报名审核选中提交订单 
	*
	*/	
	public function addok($id){

			 $taskdata['id']= (int)$id;
			 $taskdata['is_win']= 1;
			 $taskdata['updatetime']= time();
			 if($taskdata['id']){
			 $this->m_bm->save($taskdata);    //报名task_item更新记录状态
						$taskitem=M_S('task_item')->where(array('id'=>(int)$taskdata["id"]))->find();
						$in_name=M_S('task')->where(array('id'=>(int)$taskitem["task_id"]))->getField('in_name');
						$mobile=M('member')->where('id='.$taskitem['uid'])->getField('mobile'); //达人手机
						   send_sms_skill($mobile,$in_name);//提醒达人报名录取
			 }
		     return true;  
	}
	
   public function addel($id){


			 $taskdata['id']= (int)$id;
			 $taskdata['is_win']= 2;
			 $taskdata['updatetime']= time();
			 if($taskdata['id']){
			 $this->m_bm->save($taskdata);    //报名没有被选中
			 }
			 return true;
			              
	}
	/** 2016-4-28 任务报名审核选中提交订单 
	*
	*/
	
	public function add(){
		$uid=$this->userid;   
		$idstop=str_replace('&quot;','',I('id'));
		$idstop=str_replace('"','',$idstop);
		$ids= $idstop?json_decode($idstop,true):"";  //选中通过报名的记录ID
		$task_id=I('task_id'); // 任务ID  [1]
		$databm = $this->m_bm->field('id,skill_id')->where("task_id=".$task_id)->order('id desc')->select();	
		if($databm){
		foreach($databm as $key=>$item){
		if(in_array($item['id'],$ids)){   
		   $this->addok($item['id']);   //跟新报名表的审核状态
		   $info=$this->addorder($uid,$task_id,$item['id'],$item['skill_id']);//审核通过生成单个订单
		   }else{
		   // $this->addel($item['id']); 
		   }}}
		if($info){
		returnApiresult('0','成功');exit;
		}else{
		returnApiresult('1','失败');exit;
		} 
	}
	
		/** 2016-7-6  生成订单 
	*
	*/	
	public function addorder($task_uid,$task_id,$task_item_id,$skill_id){  //生产多个订单
	        $uid=$task_uid;
			$data["id"]=Getmysql_Idstr(4);
		    $data["uid"]=$uid;
			$data["order_no"]=GetorderStr();
			$data["addtime"]= time();
			$infoid = $this->m_order->add($data);
			if($infoid){
			$dataitem["id"]=Getmysql_Idstr(5);
		    $dataitem["task_id"]=(int)$task_id;
			$dataitem["task_item_id"]=(int)$task_item_id;
			$dataitem["task_name"]=M_S('task')->where('id='.$dataitem["task_id"])->getField('in_name');
			$dataitem["order_id"]= $infoid;
			$dataitem["classone"]= M_S('task')->where('id='.$dataitem["task_id"])->getField('classone');
			$dataitem["skill_price"]= M_S('skill')->where('id='.$skill_id)->getField('price');
			$dataitem["skill_unit"]=  M_S('skill')->where('id='.$skill_id)->getField('unit');
			$info = $this->m_order_n->add($dataitem);
			}
			if($info){	
			return $infoid;
			}else{
			return 0;
			}	  
	}
	
/*	public function add(){
	        $uid=$this->userid;
	       // $ids=I('post.id');  //选中通过报名的记录ID
		   
			$idstop=str_replace('&quot;','',I('id'));
			$idstop=str_replace('"','',$idstop);

			$ids= $idstop?json_decode($idstop,true):"";  //选中通过报名的记录ID
		    $task_id=I('task_id'); // 任务ID
			
			$number=M_S('task')->where('id='.$task_id)->getField('number');  //验证报名人数是否达到需求数
			if(count($ids)!=$number){
			  returnApiresult('1','选择人数不等于需求人数，无法生成订单');exit;
			}
			
			$databm = $this->m_bm->field('id')->where("task_id=".$task_id)->order('id desc')->select();	

			if($databm){
			foreach($databm as $key=>$item){
			if( in_array($item['id'],$ids)){  $this->addok($item['id']);    }else{ $this->addel($item['id']);}
			                              }
			        }

			$data["id"]=Getmysql_Idstr(4);
		    $data["uid"]=$uid;
			$data["order_no"]=GetorderStr();
			$data["addtime"]= time();
			
			$infoid = $this->m_order->add($data);
			
			if($infoid){
			$dataitem["id"]=Getmysql_Idstr(5);
		    $dataitem["task_id"]=(int)$task_id;
			$dataitem["task_name"]=M_S('task')->where('id='.$dataitem["task_id"])->getField('in_name');
			$dataitem["order_id"]= $infoid;
			$dataitem["classone"]= M_S('task')->where('id='.$dataitem["task_id"])->getField('classone');
			$info = $this->m_order_n->add($dataitem);
			}

			if($info){
			
    		M_S('task')->where("id=".$task_id)->setField('status',3);  //mysql任务进行，状态更新，跳出2的已托管可查看状态
			$mgstatus['status']=(int)3;
			$mgwhere['id']=(int)$task_id;
			M_G('task')->update($mgwhere,$mgstatus);  //mongo任务进行，状态更新，跳出2的已托管可查看状态
			
			
			returnApiresult('0','成功');exit;
			}else{
			returnApiresult('1','失败');exit;
			}
				
		  
	}*/

	
	/** 2016-4-28 创建订单号 
	*
	*/	
		public function creatOrderNo(){
		$orderNo = date("YmdHis").rand(1000, 9999);
		$isCount = $this->m_order->where(array('order_no'=>$orderNo))->count();
		if($isCount){
		$this->creatOrderNo();
		}
		return $orderNo;
	}
	
	
		/** 2016-9-14   //提醒任务主托管佣金
	*
	*/	
	 public function ts_trust(){ 
	 
	             $order_id=I('order_id');
				 $is_tx=M_S('order_item')->where("order_id='".$order_id."'")->getField("is_tx");
				 if($is_tx==1){  returnApiresult("1","已经提醒过了");exit;     }
		            $uid=M_S('order')->where("id='".$order_id."'")->getField("uid");
					$task_name=M_S('order_item')->where("order_id='".$order_id."'")->getField("task_name");
				    $msg="请给".$task_name."任务进行佣金托管";
			    	//$this->hx_send_txt_order($this->userid,$uid,$msg);
		         M_S('order_item')->where("order_id='".$order_id."'")->setField('is_tx',1);
				returnApiresult("0","提醒已发出");exit;
	 }
	 
			/** 2016-9-14   //延长支付时间
	*
	*/	
		public function long_pay(){ 
	//	echo 1;exit;
		
		         $order_id=I('order_id');
				 $is_longtime=M_S('order_item')->where("order_id='".$order_id."'")->getField("is_longtime");
				 if($is_longtime==1){  returnApiresult("1","支付时间已经延长过了");exit;     }
				 $auto_paytime=M_S('order_item')->where("order_id='".$order_id."'")->getField("auto_paytime");
				 if($order_id){
				 $auto_paytime=strtotime("+15 day",$auto_paytime?$auto_paytime:time());
				 M_S('order_item')->where("order_id='".$order_id."'")->setField('auto_paytime',$auto_paytime);
	             M_S('order_item')->where("order_id='".$order_id."'")->setField('is_longtime',1);
				 }
				 
			     returnApiresult("0","支付时间延长15天");exit;
		
				
	 } 


}